<template>
    <div>
        <!-- 权限列表 -->
        <h1>权限列表</h1>
        <!-- 面包屑 -->
        <el-breadcrumb separator-class="el-icon-arrow-right">
            <el-breadcrumb-item><a href="#">首页</a></el-breadcrumb-item>
            <el-breadcrumb-item>权限管理</el-breadcrumb-item>
            <el-breadcrumb-item>权限列表</el-breadcrumb-item>
        </el-breadcrumb>
        <!-- 卡片 -->
        <el-card class="box-card">
            <!-- 表格 -->
            <el-table :data="tableData" stripe style="width: 100%" :border="true">
                <el-table-column type="index" label="#" width="50">
                </el-table-column>
                <el-table-column prop="authName" label="权限名称" width="440">
                </el-table-column>
                <el-table-column prop="path" label="路径" width="440">
                </el-table-column>
                <el-table-column prop="address" label="权限等级">
                    <template slot-scope="scope">
                        <el-col :span="6">
                            <div class="grid-content bg-purple">
                                <el-tag v-if="scope.row.level == 0">一级</el-tag>
                                <el-tag v-if="scope.row.level == 1" type="success">二级</el-tag>
                                <el-tag v-if="scope.row.level == 2" type="warning">三级</el-tag>
                            </div>
                        </el-col>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页 -->
            <div class="block">
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pagenum"
                    :page-sizes="[5, 10, 15, 20]" :page-size="pagesize" layout="total, sizes, prev, pager, next, jumper"
                    :total="total">
                </el-pagination>
            </div>
        </el-card>
    </div>
</template>
<script>
import { prmion } from '../request/Api'
export default {
    data() {
        return {
            tableData: [{
                authName: '',
                path: '',
            }],
            pagenum: 1,
            pagesize: 5,
            total: 0,
        }
    },
    created() {
        this.getlist()

    },
    methods: {
        getlist(){
            prmion('list').then(res => {
                console.log(res);
                this.tableData = res.data.data.slice((this.pagenum-1)*this.pagesize,this.pagenum*this.pagesize) 
                
                this.total = res.data.data.length
            })
        },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.pagesize = val
            this.getlist()
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.pagenum = val
            this.getlist()
        }
    },
}
</script>
<style lang="scss" scoped>
.box-card {
    width: 96%;
    margin: 20px auto;
}
</style>